import { createClient } from 'redis'
import { throttle } from 'roc-utils'

import { REDIS_HOST, REDIS_PORT } from './config.js'

const redisClient = createClient({
    socket: {
        host: REDIS_HOST,
        port: REDIS_PORT,
    },
})

redisClient.on(
    'error',
    throttle((err) => {
        console.error('redis连接失败:', err)
    }, 10000),
)

redisClient.connect().then(() => {
    console.log('redis连接成功~')
})

export default redisClient
